package com.mrper.jnindk;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.AppCompatSeekBar;
import android.view.SurfaceView;
import android.view.View;
import android.widget.ImageView;
import android.widget.SeekBar;

public class PlayerActivity extends AppCompatActivity {

    private Player player;
    private int value = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_player);
        SurfaceView surfaceView = (SurfaceView)findViewById(R.id.surfaceView);
        AppCompatSeekBar seekBar = (AppCompatSeekBar)findViewById(R.id.seekBar);
        player = new Player(surfaceView,seekBar);
        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            private int a_progress;
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                a_progress = progress * player.mediaPlayer.getDuration() / seekBar.getMax();
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                player.mediaPlayer.seekTo(a_progress);
            }
        });
        findViewById(R.id.imgPlayControl).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(value == 0){
                    player.playUrl("http://192.168.137.1/w.mp4");
                    value = 1;
                    ((ImageView)v).setImageResource(R.drawable.ic_pause_black);
                }else{
                    player.pause();
                    value = 0;
                    ((ImageView)v).setImageResource(R.drawable.vector_play_arrow_black);
                }
            }
        });
    }

}
